package com.example.taximeter.mapper;

import com.example.taximeter.bean.Taximeter;
import com.example.taximeter.bean.User;
import com.example.taximeter.bean.UserLog;
import com.example.taximeter.bean.UserView;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 用户
 */
@Mapper
public interface UserMapper {

    //查询用户（用户名）
    @Select("select * from tab_base_user where user_name = #{username,jdbcType=VARCHAR}")
    List<User> findUserByUsername(String username);


    //查询用户（userid）
    @Select("select * from tab_base_user where id = #{userid,jdbcType=INTEGER}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "user_name"),
            @Result(property = "passwd", column = "passwd"),
            @Result(property = "fullname", column = "full_name"),
            @Result(property = "usersex", column = "user_sex"),
            @Result(property = "roleid", column = "role_id"),
            @Result(property = "userstat", column = "user_stat"),
            @Result(property = "userexp", column = "user_exp"),
            @Result(property = "memo", column = "memo"),
    })
    User findUserByUserid(Integer userid);


    @SelectProvider(type = ActivityMapperProvider.class, method = "findUserAll")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "user_name"),
            @Result(property = "passwd", column = "passwd"),
            @Result(property = "fullname", column = "full_name"),
            @Result(property = "usersex", column = "user_sex"),
            @Result(property = "roleid", column = "role_id"),
            @Result(property = "userstat", column = "user_stat"),
            @Result(property = "userexp", column = "user_exp"),
            @Result(property = "memo", column = "memo"),
            @Result(property = "rolename", column = "role_name"),
            @Result(property = "companyname", column = "company_name")

    })
    List<UserView> findUserAll(UserView userView);

    //查询用户名列表
    @Select("select id , user_name from tab_base_user")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "user_name")
    })
    List<User> findUsernameList();

    //查询用户全称列表
    @Select("select id , full_name from tab_base_user")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "fullname", column = "full_name")
    })
    List<User> findFullnameList();

    //新增用户信息
    @Insert("insert into tab_base_user (user_name, passwd, user_sex, \n" +
            "      full_name, user_exp, user_stat, role_id, memo,company_id)\n" +
            "    values (#{username,jdbcType=VARCHAR}, #{passwd,jdbcType=VARCHAR}, #{usersex,jdbcType=INTEGER}, \n" +
            " #{fullname,jdbcType=VARCHAR}, #{userexp,jdbcType=DATE}, #{userstat,jdbcType=INTEGER}, \n" +
            "#{roleid,jdbcType=INTEGER}, #{memo,jdbcType=VARCHAR},#{companyid,jdbcType=INTEGER}) ")
    Boolean addUser(User user);

    //修改用户信息
    @Update("update tab_base_user set user_name = #{username,jdbcType=VARCHAR},user_sex = #{usersex,jdbcType=INTEGER},user_stat = #{userstat,jdbcType=INTEGER},role_id = #{roleid,jdbcType=INTEGER} ,passwd = #{passwd,jdbcType=VARCHAR}, full_name = #{fullname,jdbcType=VARCHAR} , user_exp = #{userexp,jdbcType=DATE},memo = #{memo,jdbcType=VARCHAR} ,company_id = #{companyid,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER}")
    boolean updateUser(UserView userView);


    //删除用户信息
    @Delete("delete from tab_base_user  where id = #{id,jdbcType=INTEGER}")
    boolean deleteUser(Integer id);

    //查询用户（userid）
    @Select("select * from user where id = #{userid,jdbcType=INTEGER}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "user_name"),
            @Result(property = "passwd", column = "passwd"),
            @Result(property = "fullname", column = "full_name"),
            @Result(property = "usersex", column = "user_sex"),
            @Result(property = "roleid", column = "role_id"),
            @Result(property = "userstat", column = "user_stat"),
            @Result(property = "userexp", column = "user_exp"),
            @Result(property = "memo", column = "memo"),
            @Result(property = "companyid", column = "company_id"),
            @Result(property = "companyname", column = "company_name"),

    })
    UserView findUserViewByUserid(Integer userid);

    //添加参数文件管理日志
    @Insert("insert into tab_user_log (user_name, log_type, \n" +
            "      log_description, s_time)\n" +
            "    values (#{username,jdbcType=VARCHAR}, #{logtype,jdbcType=INTEGER}, \n" +
            "   #{logdescription,jdbcType=VARCHAR}, #{stime,jdbcType=TIMESTAMP} )")
    void addUserLog(UserLog userLog);

}
